package cn.com.dragonsoftbravo.utils.azure.utils;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

import com.drew.imaging.ImageMetadataReader;
import com.drew.metadata.Directory;
import com.drew.metadata.Metadata;
import com.drew.metadata.Tag;

public class ExifUtils {

	private static String KEY_READ_MODEL = "Model";
	private static String KEY_READ_ISO = "ISO Speed Ratings";
	private static String KEY_READ_FNUMBER = "F-Number";
	private static String KEY_READ_EXPOSURE = "Exposure Time";

	private static String KEY_REAL_MODEL = "Model";
	private static String KEY_REAL_ISO = "ISO";
	private static String KEY_REAL_FNUMBER = "FNumber";
	private static String KEY_REAL_EXPOSURE = "Exposure Time";

	public static Map<String, String> getExifs(InputStream bis, String imageRef) throws Exception {

		Map<String, String> exifs = new HashMap<String, String>();

//		Metadata metadata = ImageMetadataReader.readMetadata(bis, false);
		Metadata metadata = null;
		for (Directory directory : metadata.getDirectories()) {
			for (Tag tag : directory.getTags()) {
				String tagName = tag.getTagName();
				String tagDesc = tag.getDescription();

				if (tagName.equals(KEY_READ_MODEL)) {
					exifs.put(KEY_REAL_MODEL, tagDesc);
					continue;
				}

				if (tagName.equals(KEY_READ_ISO)) {
					exifs.put(KEY_REAL_ISO, tagDesc);
					continue;
				}

				if (tagName.equals(KEY_READ_FNUMBER)) {
					exifs.put(KEY_REAL_FNUMBER, tagDesc);
					continue;
				}

				if (tagName.equals(KEY_READ_EXPOSURE)) {
					exifs.put(KEY_REAL_EXPOSURE, tagDesc);
					continue;
				}
			}
		}

		return exifs;
	}

}
